package com.abbas.wallerpaper.view;

import android.view.View;

import androidx.annotation.NonNull;
import androidx.viewpager.widget.ViewPager;

//首先创建一个ZoomOutPageTransformer
public class ZoomOutPageTransformer implements ViewPager.PageTransformer {
    //缩小倍数可以调节
    private static final float MAX_SCALE = 1f;
    private static final float MIN_SCALE = 0.6f;//0.85f

    @Override
    public void transformPage(@NonNull View page, float position) {


        if (position <= 1) {

            float scaleFactor = MIN_SCALE + (1 - Math.abs(position)) * (MAX_SCALE - MIN_SCALE);

            page.setScaleX(scaleFactor);

            if (position > 0) {

                page.setTranslationX(-scaleFactor * 2);

            } else if (position < 0) {

                page.setTranslationX(scaleFactor * 2);

            }

            page.setScaleY(scaleFactor);

        } else {

            page.setScaleX(MIN_SCALE);

            page.setScaleY(MIN_SCALE);
        }

    }
}